#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <fcntl.h>
#include <cerrno>
#include <cstring>
using namespace std;

void SetNoneBlock(int fd)
{
    int f1 = fcntl(fd, F_GETFL);
    if(f1 < 0)
    {
        perror("fnctl");
        return;
    }
    fcntl(fd, F_SETFL, f1 | O_NONBLOCK);
    cout << "set none block success" << endl;
}
int main()
{
    SetNoneBlock(0);
    char buffer[96];
    while(true)
    {
        // printf("Please Eneter#");
        // flush(stdout);
        ssize_t n = read(0, buffer, sizeof(buffer) - 1);
        //sleep(1);
        if(n > 0)
        {
            buffer[n - 1] = 0; 
            cout << buffer << endl;
        }
        else if(n == 0)
        {
            cout << "read done" << endl;
            break; 
        }
        else if(n < 0)
        {
            if(errno == EAGAIN)
            {
                cout << "read not ready, try again" << endl;
                sleep(1);
            }
            else 
            {
                cerr << "read errro" << endl;
                break;
            }
        }

    }
    return 0;
}